/*
 * DAC.c
 *
 * Created: 29.10.2012 14:01:46
 *  Author: bardbakk
 */ 
#include <avr/io.h>
#include <stdlib.h>
#include "definitions.h"
#include "TWI_Master.h"

#define SLAVE_ADDR_WRITE 0b01010000

void DAC_init()
{
	TWI_Master_Initialise();
	//SET SCL and SDA as ouput
	BIT_SET(DDRD, PD0);
	BIT_SET(DDRD, PD1);
}

void DAC_write(int val)
{
	unsigned char* msg = malloc(3*sizeof(char));
	unsigned char msgSize = 3;
	
	msg[0] = SLAVE_ADDR_WRITE;
	msg[1] = 0b00000000;
	msg[2] = (uint8_t)val;

	TWI_Start_Transceiver_With_Data(msg, msgSize);
	free(msg);
}
